package com.tansuo365.test1.controller.kucunstuff;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tansuo365.test1.bean.kucunbean.WuliaoKucunSear;
import com.tansuo365.test1.service.kucunservice.WuliaoKucunSearService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/admin/wuliaokucun")
@RestController
public class WuliaoKucunSearController {

    @Resource
    private WuliaoKucunSearService wuliaoKucunSearService;

    @RequestMapping("/getSelective")
    public Map<String,Object> getKucunSelective(WuliaoKucunSear wuliaoKucunSear,@RequestParam(value = "page", required = true) Integer page, @RequestParam(value = "rows", required = true) Integer rows){
        if (wuliaoKucunSear == null) {
            return null;
        }
        Map<String, Object> resultMap = new HashMap<>();
        PageHelper.startPage(page, rows);
        List<WuliaoKucunSear> wuliaoKucunList = wuliaoKucunSearService.listKucunSelective(wuliaoKucunSear);
        PageInfo<WuliaoKucunSear> pageInfo = new PageInfo<WuliaoKucunSear>(wuliaoKucunList);
        resultMap.put("rows", pageInfo.getList());
        resultMap.put("total", pageInfo.getTotal());
        return resultMap;
    }

//    @RequestMapping("/save")
//    public Map<String, Object> save(HttpSession session, DaohuoZong daohuoZong, @RequestParam("wuliaoDaohuoDetailsJson") String wuliaoDaohuoDetailsJson) {
//        if (daohuoZong == null || wuliaoDaohuoDetailsJson == null) {
//            return null;
//        }
//        Map<String, Object> resultMap = new HashMap<>();
//        Gson gson = new Gson();
//        List<DaohuoDetails> daohuoDetailsList = gson.fromJson(wuliaoDaohuoDetailsJson, new TypeToken<List<DaohuoDetails>>() {
//        }.getType());
//
//        daohuoZong.setFounder((String) session.getAttribute("truename"));
//        //save时,先保存大表,大表返回id后再保存附表
//        int insertCode = daohuoZongService.saveZongAndDetails(daohuoZong, daohuoDetailsList);
//        //save时,保存到货单数据到申购执行,选择其中daohuoDetailsList中shengoudanhao不为空的进行保存转换
//        int zhixingSaveCode = shengouZhixingService.saveDaohuoBindShengou(daohuoDetailsList, daohuoZong);
//        if (insertCode > 0 && zhixingSaveCode == 0) {
//            resultMap.put("success", true);
//            resultMap.put("msg", "保存成功.");
//
//
////            wuliaoKucunSearService.
//        } else if (insertCode > 0 && zhixingSaveCode > 0) {
//            resultMap.put("success",true);
//            resultMap.put("msg","保存成功!!");
//        } else {
//            resultMap.put("success", false);
//            resultMap.put("errorInfo", "保存失败");
//        }
//        return resultMap;
//    }
}
